<?php

function list_karyawan_by_periode_id( ){

	$periode_id =get_periode_absen();
	$periode = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$bulan = (int) date('m' , strtotime($periode['tanggal']));
	$tahun = (int) date('Y' , strtotime($periode['tanggal']));
	$end=$periode['tahun'].'-'. sprintf( '%02d',$bulan) .'-10' ;
	$header = array(
		'#'=>array('style'=>'border-bottom:2px solid;width:5%'),
		'nik'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),
		'nama'=>array('style'=>'border-bottom:2px solid;width:60%'),
	//	'waktu kerja'=>array('style'=>'border-bottom:2px solid;width:10%'),
	//	'kelompok shift'=>array('style'=>'border-bottom:2px solid;width:10%'),
		' '=>array('style'=>'border-bottom:2px solid;width:5%'), 
	);
	if(isset($_GET['key'])){
		$query = "
			SELECT * FROM karyawan a 
			INNER JOIN biodata b 
			ON a.biodata_id = b.biodata_id
			WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)	
			AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian  WHERE TMT <= '{$end}') 	
			AND ( b.nama LIKE '%{$_GET['key']}%' OR a.nik='{$_GET['key']}')
			ORDER BY a.nik
		";
	}else{
		$query = "
			SELECT * FROM karyawan a 
			INNER JOIN biodata b 
			ON a.biodata_id = b.biodata_id
			WHERE a.karyawan_id NOT IN (select karyawan_id FROM karyawan_disable)	
			AND a.karyawan_id NOT IN (select karyawan_id FROM pemberhentian  WHERE TMT <= '{$end}') 	
			ORDER BY a.nik
		";
		
	}
	$result = my_query($query);
	$total_records = my_num_rows($result );
	$scroll_page =5;   
	$per_page =30;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}&key={$_GET['key']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	 
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 	
	$row = array(); 
	$i = ($current_page  - 1 ) * 30; 
	while($ey = my_fetch_array($result )){
		$i++;
		$karyawan =  loaddata_karyawan($ey['karyawan_id']); 
		if(empty($karyawan['kelompok'])){
			$detail_button = button_icon( 'b_props.png' , ''  );
		}else{
			$detailproperty = array(
					'href'=>'index.php?com=realisasi_wk_karyawan&task=absenperkaryawan&karyawan_id='.$ey['karyawan_id'], 
					'title'=>'Detail absensi '.$ey['nama']
			);
			$detail_button = button_icon( 'b_props.png' , $detailproperty  );
		}
		$row[] = array(
			'#'=>position_text_align ($i, 'center'), 
			'nik'=>position_text_align( $ey['nik'], 'center'),
			'nama'=>$ey['nama'],  
		//	'wk'=>position_text_align( $karyawan['waktu_kerja'] , 'center'), 
		//	'kel'=>position_text_align( $karyawan['kelompok'] , 'center'), 
			'operasi'=> position_text_align( $detail_button  , 'right'),  
		);
		
	}
	
	$datas = table_rows($row); 
	$paging = $kgPagerOBJ ->showPaging();
	
	$view =  form_header( "detail pegawai" , "cp"  );
	$view .= form_field_display( '<span class="label_form">'. get_tanggal_by_periode_id() .'</span>'   , "<b>Periode Absen</b>"    ); 
	$view .= form_footer( );
	$search = '<form method="GET"><input type="hidden" name="com" value="'.$_GET['com'].'" /><span style="font:10px verdana"><b>Pencarian cepat</b></span><br/><input type="text"  style="width:200px;" name="key" value="'.(isset($_GET['key']) ? $_GET['key']: "").'" /><input class="simple_search" type="submit" value=" CARI " /> </form>';
	$printmenu = additional_menu_on_list( array(), $search);
	return  $view.$printmenu .table_builder($header , $datas ,  15 ,false ,$paging );
}

function get_tanggal_by_periode_id(){
	$periode_id =get_periode_absen();
	$periodes = my_get_data_by_id('pr_periode','periode_id',$periode_id);
	$bulan = (int) date('m' , strtotime($periodes['tanggal']));
	$tahun = $periodes['tahun'] ;
	return sprintf( '%02d',$bulan).'-'.$tahun ;
}




function list_periode(){
	$header = array(
		'Tahun'=>array('style'=>'border-bottom:2px solid;width:50%'),  
		'Bulan'=>array('style'=>'text-align:left;border-bottom:2px solid;width:40%'),   
		' '=>array('style'=>'border-bottom:2px solid;width:10%'), 
	);
	
	$query = "SELECT * FROM pr_periode ORDER BY periode_id ASC";
	$result = my_query($query);
	$row = array();
	while( $ey =my_fetch_array($result) ){
		$detailpajak = array(
						'href'=>'index.php?com='.$_GET['com'].'&task=detail_periode&periode_id='.$ey['periode_id'],
						'title'=>'Detail periode'
				);
		$detail_pajak_button = button_icon( 'b_props.png' , $detailpajak  );
		
		$row[] = array(
			'tahun'=>$ey['tahun'],
			'bulan'=>date('m',strtotime($ey['tanggal'])),
			' v'=>position_text_align($detail_pajak_button,'right'),
		);
	}
	$datas = table_rows($row);
	 return   table_builder($header , $datas ,  5 , false);
}

